* Calculate monetary value of time saved by the CAP
* 7/1/24

clear all
set more off

program main
	calculate_pdv, rate(test)
	calculate_pdv, rate(shapiro)
	calculate_pdv, rate(high_credit)
end

program calculate_pdv
	syntax, rate(str)

	local test = 0.1
	local shapiro = round((1+1.46)^(1/12)-1, 0.001)
	local high_credit = round((1+0.25)^(1/12)-1, 0.001)
	if "`rate'" == "test" {
		local int_rate = `test'
	}
	else if "`rate'" == "shapiro" {
		local int_rate = `shapiro'
	}
	else if "`rate'" == "high_credit" {
		local int_rate = `high_credit'
	}

	clear 
	qui set obs 12
	qui gen month = .
	qui gen value = .
	forval i = 1/12 {
		qui replace month = `i' if _n == `i'
		qui replace value = 114 / (1 + `int_rate')^`i' if _n == `i'
	}
	egen PDV = total(value)
	local PDV = round(PDV[1], 0.01)
	
	qui gen value_hour = PDV / 5
	local value_hour = round(value_hour[1], 0.01)
	qui gen new_cost = 3 * value_hour
	local new_cost = round(new_cost[1], 0.01)
	local surplus = round(PDV - new_cost, 0.01)
	
	di "Rate `rate': PDV=`PDV'; v=`value_hour'; new cost=`new_cost'; saves $`surplus'."
end

* Execute
main
